//
//  XKPageView.swift
//  XKPageView
//
//  Created by 徐凯 on 2017/6/6.
//  Copyright © 2017年 XK. All rights reserved.
//

import UIKit

class XKPageView: UIView {
    
    // MARK:- 属性
    var titles : [String]
    var style : XKPageStyle
    var childVCs : [UIViewController]
    var parentVC : UIViewController
    

    // MARK:- 构造函数
    init(frame: CGRect, titles : [String], style : XKPageStyle, childVCs : [UIViewController], parentVC : UIViewController) {
        
        
        self.titles = titles
        self.style = style
        self.childVCs = childVCs
        self.parentVC = parentVC;
        super.init(frame: frame)
        setupUI()
        
        
    }
    
    // 自定义构造函数 必须用required修饰构造函数
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    
    
}

// MARK:- 设置UI

extension XKPageView
{
    
    // 在extension中的私有方法不能在使用private 要使用fileprivate文件私有
    fileprivate func setupUI()
    {
        self.backgroundColor = UIColor.white
        
        // 创建titleView
        
        let titleView = XKTitleView(frame: CGRect(x: 0, y: 0, width: self.bounds.width, height: self.style.titleHight), titles: titles, style: style)
        titleView.backgroundColor = UIColor.orange
        addSubview(titleView)
        
        // 创建contentView
        let contentView = XKContentView(frame: CGRect(x: 0, y: titleView.frame.maxY, width: self.bounds.width, height: self.bounds.height - titleView.frame.height), childVCs: childVCs, parentVC: parentVC)
        contentView.backgroundColor = UIColor.blue
        addSubview(contentView)
        
    }
}
